
#include <QPushButton> 


#include "restricaoapoiodlg.h"

#include <QGraphicsScene>
#include <QGraphicsPixmapItem>

////////////////////////////////////////////////////////////
restricaoApoioDlg::restricaoApoioDlg(QWidget *parent)
	: QDialog(parent) 
{
	
   setupUi(this);
   connect( closeButton, SIGNAL( clicked() ), this, SLOT( sair() ) );
   connect( clearButton, SIGNAL( clicked() ), this, SLOT( limpar() ) );
   connect( applyButton, SIGNAL( clicked() ), this, SLOT( salvar () ) );


  
	connect(kxRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );
	connect(freeXRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );

	connect(fixXRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarValorFixX()) );// TESTE === CONSTRUIR METODO PARA KX e FREE



	connect(kyRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );
	connect(freeYRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );


	//connect(fixYRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );
	connect(fixYRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarValorFixY() ) ); //TESTE , IMPLEMENTAR



	connect(kzRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );
	connect(freeZRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );


    //connect(fixZRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarvalorX() ) );
	connect(fixZRadioButton, SIGNAL(toggled(bool)), this, SLOT(apontarValorFixZ() ) ); //TESTE , IMPLEMENTAR




	connect(prescribedCheckBox, SIGNAL(toggled(bool)), this, SLOT(togglePrescribedCheckBox() ) );//TESTE, IMPLEMENTAR
	

	
   //image.load(":/acmFrame/images/dialogos/restricao.png");   
   image.load(":/acmFrame/images/dialogos/restricao.png");                     
	
   this->graphicsView->setScene(new QGraphicsScene());
   this->graphicsView->scene()->addItem(new QGraphicsPixmapItem(image));


}


///////////////////////////////////////////////////////////
restricaoApoioDlg::~restricaoApoioDlg()
{

}


///////////////////////////////////////////////////////////
void restricaoApoioDlg::sair()
{
	this->close(); 
}


///////////////////////////////////////////////////////////
void restricaoApoioDlg::limpar()
{
	//this->linearModElast->setText("0.00");
	this->kx->setText("0.00");
	this->ky->setText("0.00");
	this->kz->setText("0.00");

	this->angle->setText("0.00");
	this->dx->setText("0.00");
	this->dy->setText("0.00");
	this->rz->setText("0.00");
	   
}


//////////////////////////////////////////////////////////////
void restricaoApoioDlg::salvar()
{
		
	*kx_d=(float)this->getkx();
	*ky_d=(float)this->getky();
	*kz_d=(float)this->getkz();

	*angle_d=(float)this->getangle();//teste
	*dx_d=(float)this->getdx();
	*dy_d=(float)this->getdy();
	*rz_d=(float)this->getrz();
	
	this->close(); 
}

//////////////////////////////////////////////////////////// 

void restricaoApoioDlg::togglePrescribedCheckBox()
{
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++ FIX_X 
 if(this->prescribedCheckBox->isChecked())
  {
	  if(this->fixXRadioButton->isChecked()) 
	  {
		  (*displacxgroup) = FIX_X;
			this->dx->setEnabled(true);
	  }
  } 
  else  
  {
	  this->dx->setText("0.00");
	  this->dx->setEnabled(false);
	  (*displacxgroup) = NADA_X;
  }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++FIX_Y
 if(this->prescribedCheckBox->isChecked())
  {
	  if(this->fixYRadioButton->isChecked()) 
	  {
		  (*displacygroup) = FIX_Y;
			this->dy->setEnabled(true);
	  }
  } 
  else  
  {
	  this->dy->setText("0.00");
	  this->dy->setEnabled(false);
	  (*displacygroup) = NADA_Y;
  }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++FIX_Z

if(this->prescribedCheckBox->isChecked())
  {
	  if(this->fixZRadioButton->isChecked()) 
	  {
		  (*rotationzgroup) = FIX_Z;
			this->rz->setEnabled(true);
	  }
  } 
  else  
  {
	  this->rz->setText("0.00");
	  this->rz->setEnabled(false);
	  (*rotationzgroup) = NADA_Z;
  }






}//FIM


////////////////////////////////////////////////////////////// FIX_X

void restricaoApoioDlg::apontarValorFixX() 
{
  if(this->fixXRadioButton->isChecked())
  {
		if(this->prescribedCheckBox->isChecked()) 
		{
			(*displacxgroup) = FIX_X;
			this->dx->setEnabled(true);
		}
  } 
  else  {
	  (*displacxgroup) = NADA_X;
	  this->dx->setText("0.00");
	  this->dx->setEnabled(false);
  }
}

////////////////////////////////////////////////////////////// FIX_Y 

void restricaoApoioDlg::apontarValorFixY() 
{
  if(this->fixYRadioButton->isChecked())
  {
		if(this->prescribedCheckBox->isChecked()) 
		{
			(*displacygroup) = FIX_Y;
			this->dy->setEnabled(true);
		}
  } 
  else  {
	  (*displacygroup) = NADA_Y;
	  this->dy->setText("0.00");
	  this->dy->setEnabled(false);
  }
}

///////////////////////////////////////////////////////////// FIX_Z


void restricaoApoioDlg::apontarValorFixZ() 
{
  if(this->fixZRadioButton->isChecked())
  {
		if(this->prescribedCheckBox->isChecked()) 
		{
			(*rotationzgroup) = FIX_Z;
			this->rz->setEnabled(true);
		}
  } 
  else  {
	  (*rotationzgroup) = NADA_Z;
	  this->rz->setText("0.00");
	  this->rz->setEnabled(false);
  }
}





////////////////////////////////////////////////////////////// APONTAR VALORES K, FIX ,FREE
void restricaoApoioDlg::apontarvalorX()
{

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++KX
  if(this->kxRadioButton->isChecked())
  {
		(*displacxgroup) = KX;

		this->kx->setEnabled(true);

  } 
  else if(this->fixXRadioButton->isChecked()) //teste
   {
		(*displacxgroup) = FIX_X;
		
		this->kx->setText("0.00");
		this->kx->setEnabled(false);

	   	
  }
  else if(this->freeXRadioButton->isChecked())
  {
		(*displacxgroup) = FREE_X;

		this->kx->setText("0.00");
		this->kx->setEnabled(false);

        
  }

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++KY
 if(this->kyRadioButton->isChecked())
  {
		(*displacygroup) = KY;

		this->ky->setEnabled(true);

  } 
  else if(this->fixYRadioButton->isChecked())
   {
		(*displacygroup) = FIX_Y;
		
		this->ky->setText("0.00");
		this->ky->setEnabled(false);

	     		
  }
  else if(this->freeYRadioButton->isChecked())
  {
		(*displacygroup) = FREE_Y;

		this->ky->setText("0.00");
		this->ky->setEnabled(false);

		
  }

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ KZ
if(this->kzRadioButton->isChecked())
  {
		(*rotationzgroup) = KZ;

		this->kz->setEnabled(true);

  } 
  else if(this->fixZRadioButton->isChecked())
   {
		(*rotationzgroup) = FIX_Z;
		
		this->kz->setText("0.00");
		this->kz->setEnabled(false);
		 
   }
  else if(this->freeZRadioButton->isChecked())
  {
		(*rotationzgroup) = FREE_Z;

		this->kz->setText("0.00");
		this->kz->setEnabled(false);


   }

} 

///////////////////////////////////////////////////////////////
void restricaoApoioDlg::setDisplacXgroup (DisplacXgroup *displacxgroup)
{
	this->displacxgroup=displacxgroup;

	springGroupBox->setEnabled(true);    //grupo kx , ky , kz 

	
	switch (*displacxgroup)
	{
	case FREE_X:
		this->freeXRadioButton->toggle();
		

		this->kx->setText("0.00");
		this->kx->setEnabled(false);

				
		break;

	case FIX_X:
		this->fixXRadioButton->setChecked(true);
		this->prescribedCheckBox->setChecked(true); //teste

		this->kx->setText("0.00");
		this->kx->setEnabled(false);


		prescribedGroupBox->setEnabled(true);//controla visibilidade do grupo DX, DY , RZ


		break;

	case KX:
		this->kxRadioButton->toggle();
		
					
		this->kx->setEnabled(true);

		
		break;
	}

}

////////////////////////////////////////////////////////////
void restricaoApoioDlg::setDisplacYgroup (DisplacYgroup *displacygroup)
{
	this->displacygroup=displacygroup;

	//this->freeYRadioButton->setChecked(false);
	//this->fixYRadioButton->setChecked(false);
	//this->kyRadioButton->setChecked(false);

	springGroupBox->setEnabled(true);

	

	switch (*displacygroup)
	{
	case FREE_Y:
		this->freeYRadioButton->toggle();


		this->ky->setText("0.00");
		this->ky->setEnabled(false);


		break;

	case FIX_Y:
		this->fixYRadioButton->toggle();
        this->prescribedCheckBox->setChecked(true); //teste

		this->ky->setText("0.00");
		this->ky->setEnabled(false);


		prescribedGroupBox->setEnabled(true);//controla visibilidade do grupo DX, DY , RZ

		break;

	case KY:
		this->kyRadioButton->toggle();
		
					
		this->ky->setEnabled(true);

		

		break;
	}

}

////////////////////////////////////////////////////////////////
void restricaoApoioDlg::setRotationZgroup (RotationZgroup *rotationzgroup)
{
	this->rotationzgroup=rotationzgroup;
	
	//this->freeZRadioButton->setChecked(false);
	//this->fixZRadioButton->setChecked(false);
	//this->kzRadioButton->setChecked(false);

	springGroupBox->setEnabled(true);


	switch (*rotationzgroup)
	{
	case FREE_Z:
		this->freeZRadioButton->setChecked(true);

	
		this->kz->setText("0.00");
		this->kz->setEnabled(false);


		
		break;

	case FIX_Z:
		this->fixZRadioButton->toggle();
		this->prescribedCheckBox->setChecked(true); //teste


		this->kz->setText("0.00");
		this->kz->setEnabled(false);


		prescribedGroupBox->setEnabled(true);//controla visibilidade do grupo DX, DY , RZ


		break;

	case KZ:
		this->kzRadioButton->toggle();
		
					
		this->kz->setEnabled(true);

	
		break;
	}

}

/////////////////////////////////////////////////////////////////////////////////// KX
float restricaoApoioDlg::getkx()
{
	return this->kx->text().toFloat();  
}


void restricaoApoioDlg::setkx(float *kx) 
{	
	this->kx_d = kx;
	this->kx->setText(QString::number(*kx,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// KY

float restricaoApoioDlg::getky()
{
	return this->ky->text().toFloat();  
}


void restricaoApoioDlg::setky(float *ky) 
{	
	this->ky_d = ky;
	this->ky->setText(QString::number(*ky,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// KZ
float restricaoApoioDlg::getkz()
{
	return this->kz->text().toFloat();  
}


void restricaoApoioDlg::setkz(float *kz) 
{	
	this->kz_d = kz;
	this->kz->setText(QString::number(*kz,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// ANGLE

float restricaoApoioDlg::getangle()
{
	return this->angle->text().toFloat();  
}


void restricaoApoioDlg::setangle(float *angle) 
{	
	this->angle_d = angle;
	this->angle->setText(QString::number(*angle,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// DX
float restricaoApoioDlg::getdx()
{
	return this->dx->text().toFloat();  
}


void restricaoApoioDlg::setdx(float *dx) 
{	
	this->dx_d = dx;
	this->dx->setText(QString::number(*dx,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// DY
float restricaoApoioDlg::getdy()
{
	return this->dy->text().toFloat();  
}


void restricaoApoioDlg::setdy(float *dy) 
{	
	this->dy_d = dy;
	this->dy->setText(QString::number(*dy,'f',2));
   
}

///////////////////////////////////////////////////////////////////////////////////// RZ
float restricaoApoioDlg::getrz()
{
	return this->rz->text().toFloat();  
}


void restricaoApoioDlg::setrz(float *rz) 
{	
	this->rz_d = rz;
	this->rz->setText(QString::number(*rz,'f',2));
   
}

/////////////////////////////////////////////////////////////////////////////////////